unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus,
  Oracle,
  cxLookAndFeelPainters, StdCtrls, cxButtons,
  ADODB, cxGraphics, cxCustomData, cxStyles, cxTL, cxControls,
  cxInplaceContainer, ComCtrls, cxLookAndFeels, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinFoggy, dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinXmas2008Blue, FormBaseMain,
  dxSkinscxPCPainter, dxSkinsdxStatusBarPainter, dxSkinsdxBarPainter, dxBar,
  cxClasses, dxStatusBar, dxLayoutControl, dxBarExtItems, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxLayoutContainer;

type
  TfmMain = class(TfmBaseMain)
    btnDbCreate: TdxBarButton;
    btnDatabase: TdxBarSubItem;
    btnMetadataCopy: TdxBarButton;
    sbrMainContainer2: TdxStatusBarContainerControl;
    ProgressBar: TProgressBar;
    btnProjectOpen: TdxBarButton;
    btnProject: TdxBarSubItem;
    btnDbConvert: TdxBarButton;
    procedure btnDbCreateClick(Sender: TObject);
    procedure btnMetadataCopyClick(Sender: TObject);
    procedure btnProjectOpenClick(Sender: TObject);
    procedure btnDbConvertClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmMain: TfmMain;

const
  iObjNum = 0;
  iObjName = 1;

  ORA_OWNER = 'UD_N_PVDES_ADM';

implementation

uses
  FormUtils,
  MainDatamodule, Project_DM, DbCreate, DbConvert, Convert, Project, DbManager;
{$R *.dfm}

procedure TfmMain.btnDbConvertClick(Sender: TObject);
begin
  inherited;
  ShowMDIForm(TfmDbConvert);
end;

procedure TfmMain.btnDbCreateClick(Sender: TObject);
begin
  inherited;
  ShowMDIForm(TfmDbCreate);
end;

procedure TfmMain.btnMetadataCopyClick(Sender: TObject);
begin
{
  if dmMain.ConnectToDB then
  begin
    CreateAllTables(dbtOracle);
    // AddUnique('ctr_contract','AGRAGREEMENT');
    // AddUnique('gls_owner','cw_id');
    if CreateAllRelations and dmMain.conTarget.InTransaction then
      dmMain.conTarget.CommitTrans;
  end;
 }
end;

procedure TfmMain.btnProjectOpenClick(Sender: TObject);
var
  fmDbManager: TfmDbManager;
  fmProject: TfmProject;
begin
  inherited;

  {
  fmProject := TfmProject(ShowMDIForm(TfmProject));
  fmProject.oraSession.LogonDatabase := 'DBASEN';
  fmProject.oraSession.LogonUsername := 'PHP_SYS_ADM';
  fmProject.oraSession.LogonPassword := 'PHP';
  fmProject.oraSession.ConnectAs := caNormal;
  fmProject.oraSession.Connected := true;

  fmProject.P_OWNER := 'PHP_SYS_ADM';

  fmProject.dsObjects.Close;
  fmProject.dsObjects.SetVariable('P_OWNER', fmProject.P_OWNER);
  fmProject.dsObjects.Open;

  exit;


  fmProject := TfmProject(ShowMDIForm(TfmProject));
  fmProject.oraSession.LogonDatabase := 'DBASEN';
  fmProject.oraSession.LogonUsername := 'ORT_ADM';
  fmProject.oraSession.LogonPassword := 'ORT';
  fmProject.oraSession.ConnectAs := caNormal;
  fmProject.oraSession.Connected := true;

  fmProject.P_OWNER := 'ORT_ADM';

  fmProject.dsObjects.Close;
  fmProject.dsObjects.SetVariable('P_OWNER', fmProject.P_OWNER);
  fmProject.dsObjects.Open;

  exit;
 }
{
  fmProject := TfmProject(ShowMDIForm(TfmProject));
  fmProject.oraSession.LogonDatabase := 'DBASEN';
  fmProject.oraSession.LogonUsername := 'OVL_ADM';
  fmProject.oraSession.LogonPassword := 'OVL';
  fmProject.oraSession.ConnectAs := caNormal;
  fmProject.oraSession.Connected := true;

  fmProject.P_OWNER := 'OVL_ADM';

  fmProject.dsObjects.Close;
  fmProject.dsObjects.SetVariable('P_OWNER', fmProject.P_OWNER);
  fmProject.dsObjects.Open;

  exit;
 }


  fmDbManager := TfmDbManager.Create(Self);
  try
    if fmDbManager.ShowModal = mrOk then
    begin
      fmProject := TfmProject(ShowMDIForm(TfmProject));

      dmProject.oraSession.Connected := False;
      dmProject.oraSession.LogonDatabase := fmDbManager.dsDbList['DB_NAME'];
      dmProject.oraSession.LogonUsername := fmDbManager.dsDbList['DB_USER'];
      dmProject.oraSession.LogonPassword := fmDbManager.dsDbList['DB_PASSWORD'];

      if fmDbManager.dsDbList['DB_ROLE'] = 'SYSDBA' then
        dmProject.oraSession.ConnectAs := caSYSDBA
      else
        dmProject.oraSession.ConnectAs := caNormal;

      dmProject.oraSession.Connected := true;

      fmProject.P_OWNER := UpperCase(VarToStr(fmDbManager.dsDbList['DB_USER']));
      dmProject.SetCurrentSchema(fmProject.P_OWNER);

      fmProject.dsObjects.Close;
      //fmProject.dsObjects.SetVariable('P_OWNER', fmProject.P_OWNER);
      fmProject.dsObjects.Open;

      dmProject.dsUser.Open;
      fmProject.tshProject.Caption := VarToStr(dmProject.dsUser['USER']);
    end;
  finally
    fmDbManager.Free;
  end;
end;

end.
